export const getMediaPermission = () => {
  return new Promise((resolve, reject) => {
    plus.android.requestPermissions(
      ["android.permission.CAMERA", "android.permission.RECORD_AUDIO"],
      function (e) {
        console.log(e, "permission");
        if (e.deniedAlways.length > 0) {
          //权限被永久拒绝
          // 弹出提示框解释为何需要定位权限，引导用户打开设置页面开启
          reject();
        }
        if (e.deniedPresent.length > 0) {
          //权限被临时拒绝
          // 弹出提示框解释为何需要定位权限，可再次调用plus.android.requestPermissions申请权限
          //alert('临时 ');
          reject();
        }
        if (e.granted.length > 0) {
          resolve();
          //权限被允许
          //调用依赖获取定位权限的代码
          //alert('允许!!! ');
        }
      },
      function (e) {
        console.log("Request Permissions error:" + JSON.stringify(e));
      }
    );
  });
};

export const getLocationPermission = () => {
  return new Promise((resolve, reject) => {
    plus.android.requestPermissions(
      ["android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"],
      function (e) {
        console.log(e, "permission");
        if (e.deniedAlways.length > 0) {
          reject();
          //权限被永久拒绝
          // 弹出提示框解释为何需要定位权限，引导用户打开设置页面开启
          //alert('永久');
        }
        if (e.deniedPresent.length > 0) {
          reject();
          //权限被临时拒绝
          // 弹出提示框解释为何需要定位权限，可再次调用plus.android.requestPermissions申请权限
          //alert('临时 ');
        }
        if (e.granted.length > 0) {
          //权限被允许
          //调用依赖获取定位权限的代码
          //alert('允许!!! ');
          resolve();
        }
      },
      function (e) {
        console.log("Request Permissions error:" + JSON.stringify(e));
      }
    );
  });
};

export const isProduction = process.env.NODE_ENV === "production";

export const isTokenFailure = () => {
  const now = new Date().getTime();
  const loginTime = localStorage.getItem("time");
  const limTime = 1000 * 60 * 15;
  const result = now - loginTime >= limTime;
  return result;
};
